home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14384 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  51 lines

  1. Path: news.netkonect.net!usenet
  2. From: Cliff Davies <cliff@witsend.netkonect.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: #include "" for large programs.
  5. Date: Sun, 14 Apr 1996 09:53:30 -0700
  6. Organization: .netkonect (customer account)
  7. Message-ID: <31712D8A.A25@witsend.netkonect.co.uk>
  8. References: <Pine.SUN.3.92.960411195730.24973A-100000@suntan>
  9. NNTP-Posting-Host: witsend.netkonect.co.uk
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.01 (Win16; I)
  14.  
  15. Carlos Diaz (CS) wrote:
  16. > Hello!
  17. >  I've been writing short two part programs using the #include "filename"
  18. > preprocessor.
  19. >  I call one file main.c and the other part2.c, for which there is a
  20. > prototype header file part2.h.
  21. >  All works well when I compile the programs, except when  part2.h has
  22. > #define constants (I've been advised by my professor to use #define for
  23. > constants over 'const type var_name'). My compiler returns a fatal error
  24. > reporting that the symbol in the #define is not defined.
  25. >  For example if #define EQUAL 0 is part of part2.h, I'm told that the
  26. > symbol EQUAL is not defined. But if I put the #define inside main.c, I'm
  27. > told that I've defined EQUAL  TWICE, once in part2.h and again within
  28. > main. The book we're using in class is not helping at all in this subject,
  29. > and I cannot figure out why everything else is recognized, except #define
  30. > constants. Can anyone here help? If the answer to this is in the FAQ, just
  31. > tell me where to download it from. Thanks!
  32. > -Carlos E. Diaz
  33.  
  34. Just a possibility here - If the defined constant is used in both main.c 
  35. and part2.c, you need to include the header in both files.
  36. It is also quite useful to include something like the following in header 
  37. files around defines and typedefs -
  38.  
  39. #ifndef __PART2
  40. #define __PART2
  41.  
  42.     #define EQUAL 0
  43.     typedef char BOOLEAN
  44.     etc...
  45.  
  46. #endif
  47.  
  48. Hope this helps you out.
  49.